﻿<Page
    x:Class="ComicViewer.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ComicViewer"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" >

    

    <Page.Resources>

        <ItemsPanelTemplate x:Key="BookFlipViewItemsPanelTemplate">
            <VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Horizontal" VirtualizationMode="Standard" CleanUpVirtualizedItemEvent="bookFlipView_CleanUpVirtualizedItemEvent" />
        </ItemsPanelTemplate>
        
        <ItemsPanelTemplate x:Key="PageFlipViewPanel">
            <VirtualizingStackPanel AreScrollSnapPointsRegular="True" Orientation="Horizontal" VirtualizationMode="Standard" CleanUpVirtualizedItemEvent="pageFlipView_CleanUpVirtualizedItemEvent" />
        </ItemsPanelTemplate>

        <ItemsPanelTemplate x:Key="ScrollViewPanelTemplate">
            <VirtualizingStackPanel HorizontalAlignment="Center" Orientation="Vertical" VirtualizationMode="Standard"  CleanUpVirtualizedItemEvent="scrollView_CleanUpVirtualizedItemEvent"/>
        </ItemsPanelTemplate>

    </Page.Resources>
    <Page.BottomAppBar>
        <AppBar Margin="0" Height="100">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="50*" />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal">
                    <Button x:Name="bttnBack" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource PreviousAppBarButtonStyle}" Click="bttnBack_Click" />
                    <StackPanel Orientation="Horizontal" x:Name="pageNoCtrl">
                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Path=CurrentPage}" FontSize="24" />
                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="/" FontSize="24" />
                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Path=LastPage}" FontSize="24" />
                    </StackPanel>
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
                    <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" >
                        <RadioButton x:Name="bttnSinglePage" Style="{StaticResource SinglePageAppBarButtonStyle}" Checked="PanelMode_Checked" GroupName="PanelMode" />
                        <RadioButton x:Name="bttnContinuousPage" Style="{StaticResource ContinuousPageAppBarButtonStyle}" Checked="PanelMode_Checked" GroupName="PanelMode" />
                        <RadioButton x:Name="bttnTwoPage" Style="{StaticResource BookAppBarButtonStyle}" Checked="PanelMode_Checked" GroupName="PanelMode" />
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center">
                        <Button x:Name="bttnGoto" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource GoAppBarButtonStyle}" Click="bttnGoto_Click"/>
                    </StackPanel>
                </StackPanel>
                <Button x:Name="bttnNext" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Style="{StaticResource NextAppBarButtonStyle}" Click="bttnNext_Click" />

            </Grid>
        </AppBar>
    </Page.BottomAppBar>
    <Page.TopAppBar>
        <AppBar Margin="0" Height="100" Opened="TopAppBar_Opened" >
            <Grid Margin="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="50*" />
                </Grid.ColumnDefinitions>
                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center">
                    <Button x:Name="bttnOpen"  VerticalAlignment="Center"  Click="bttnOpen_Click" Style="{StaticResource OpenFileAppBarButtonStyle}" />
                    <Button x:Name="bttnClose" VerticalAlignment="Center"  Click="bttnOpen_Click" Style="{StaticResource CloseComicAppBarButtonStyle}" />
                </StackPanel>
                <StackPanel Grid.Column="1" HorizontalAlignment="Center" Orientation="Horizontal" VerticalAlignment="Center" >
                    <RadioButton x:Name="bttnFitWidth" Style="{StaticResource FitWidthAppBarButtonStyle}" Checked="Zoom_Checked" GroupName="Zoom" />
                    <RadioButton x:Name="bttnFit" IsChecked="True" Style="{StaticResource FitAppBarButtonStyle}" Checked="Zoom_Checked" GroupName="Zoom" />
                    <RadioButton x:Name="bttnFreeForm" Style="{StaticResource FreeFormPageAppBarButtonStyle}" Checked="Zoom_Checked" GroupName="Zoom" />
                    <Button x:Name="bttnZoomIn" Style="{StaticResource ZoomInAppBarButtonStyle}" Click="bttnZoomIn_Click" />
                    <Button x:Name="bttnZoomOut" Style="{StaticResource ZoomOutAppBarButtonStyle}" Click="bttnZoomOut_Click" />
                </StackPanel>
                <Button x:Name="bttnRotate" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center"  Style="{StaticResource RotateAppBarButtonStyle}" Click="bttnRotate_Click" />
            </Grid>
        </AppBar>
    </Page.TopAppBar>
   
    <Grid x:Name="mainGrid">

        <Grid x:Name="comicGrid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Visibility="Collapsed" DoubleTapped="comicGrid_DoubleTapped" Tapped="comicGrid_Tapped" >
            <local:ListViewEx x:Name="continuousView" SelectionMode="None" IsItemClickEnabled="False" ItemContainerStyle="{StaticResource ScrollViewItemContainerStyle}" 
                      ItemsPanel="{StaticResource ScrollViewPanelTemplate}" DataFetchSize="1" 
                      ItemTemplate="{StaticResource ScrollViewItemTemplate}" Style="{StaticResource ScrollViewStyle}" 
                      HorizontalContentAlignment="Center" HorizontalAlignment="Center" />

            <ScrollViewer Background="{x:Null}" x:Name="pageView" HorizontalAlignment="Center" HorizontalScrollBarVisibility="{Binding Path=HorizontalScrollBarVisibility}"
                          HorizontalScrollMode="{Binding Path=HorizontalScrollMode}" VerticalScrollBarVisibility="{Binding Path=VerticalScrollBarVisibility}"
                          VerticalScrollMode="{Binding Path=VerticalScrollMode}" ZoomMode="{Binding Path=ZoomMode}" 
                          BringIntoViewOnFocusChange="False"
                          >
                <Image Width="{Binding Path=Width}" Height="{Binding Path=Height}" Stretch="{Binding Path=Stretch}" Source="{Binding Path=ImageSrc}"   />
            </ScrollViewer>
            <ScrollViewer Background="{x:Null}" x:Name="bookView" HorizontalScrollBarVisibility="{Binding Path=HorizontalScrollBarVisibility}"
                          HorizontalScrollMode="{Binding Path=HorizontalScrollMode}" VerticalScrollBarVisibility="{Binding Path=VerticalScrollBarVisibility}"
                          VerticalScrollMode="{Binding Path=VerticalScrollMode}" ZoomMode="{Binding Path=ZoomMode}"  
                          BringIntoViewOnFocusChange="False"
                          >
                <StackPanel  Background="{x:Null}" x:Name="twoPageStackPanel" HorizontalAlignment="Center" Orientation="Horizontal" FlowDirection="{Binding Path=FlowDirection}">
                    <Image x:Name="page1" Margin="0" HorizontalAlignment="Center" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Stretch="{Binding Path=Stretch}" Source="{Binding Path=ImageSrc}"  />
                    <Image x:Name="page2" Margin="0" HorizontalAlignment="Center" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Stretch="{Binding Path=Stretch}" Source="{Binding Path=ImageSrc}" />
                </StackPanel>
            </ScrollViewer>
            <FlipView x:Name="pageFlipView"  ItemTemplate="{StaticResource PageFlipViewDataItemTemplate}"  
                      ItemsPanel="{StaticResource PageFlipViewPanel}" ItemContainerStyle="{StaticResource PageFlipViewItemStyle}" Style="{StaticResource PageFlipViewStyle}" 
                      ScrollViewer.BringIntoViewOnFocusChange="False" 
                      >

            </FlipView>
            <FlipView x:Name="bookFlipView" ItemTemplate="{StaticResource BookFlipViewItemDataTemplate}" 
                      Style="{StaticResource BookFlipViewStyle}" ItemContainerStyle="{StaticResource BookFlipViewItemStyle}" ItemsPanel="{StaticResource BookFlipViewItemsPanelTemplate}" 
                      
                      ScrollViewer.BringIntoViewOnFocusChange="False" 
                      
                      >

            </FlipView>
        </Grid>
        <Grid x:Name="busyGrid" Visibility="Collapsed">
            <ProgressBar IsIndeterminate="True" ></ProgressBar>
        </Grid>
    </Grid>

</Page>
